<?php
include_once("db_factory.php");
include_once("obj_acl_member.php");

class dal_acl_member {
	//Modlular level variables
	public $_db;
	
	private $_member_id;

	function dal_acl_member(){
		$this->_db = db_factory::GetInstance();
	}//End User Constructor

	function get($id)
	{
		$obj = new obj_acl_member();
		//Load a User by id
		$SQL = "SELECT * FROM acl_member WHERE member_id= $id ";
		$results = $this->_db->ExecuteQuery($SQL);
		foreach($results as $result)
		{
			// loop through results
			$obj->set_member_id($result['member_id']);
			$obj->set_name($result['name']);
			$obj->set_password($result['password']);
			$obj->set_status($result['status']);
			
		}
		return $obj;
	}

	function save(&$obj){
		//Save User - Use EntityID to save
			$SQL = "UPDATE acl_member SET `name` = '" . $obj->get_name() ."',`password` = '" . $obj->get_password() ."',`status` = '" . $obj->get_status() ."' WHERE member_id= " . $obj->get_member_id(). "";
			return $this->_db->ExecuteNonQuery($SQL);
	}//End Save
	
	function insert(&$obj)
	{
	
			$SQL = "INSERT INTO acl_member (`name`,`password`,`status`) VALUES ('" . $obj->get_name() ."','" . $obj->get_password() ."','" . $obj->get_status() ."')";
			$this->_db->ExecuteNonQuery($SQL); 
			// After inserting User then load it
			return $this->get($this->_db->GetLastInsertedID());
	}

	function delete($id){
		//Delete User
		$SQL = "DELETE FROM acl_member WHERE member_id= $id ";
		return $this->_db->ExecuteNonQuery($SQL); 
	}//End Delete
	
	function get_all($query=NULL)
	{
	
		if($query !=NULL)
		{
			$SQL = "SELECT * FROM acl_member WHERE " . $query;
		}
		else
		{
			$SQL = "SELECT * FROM acl_member";
		}
		
		$results = $this->_db->ExecuteQuery($SQL);
		
		foreach($results as $result)
		{
			// loop through results
			$temp = new obj_acl_member();
			// loop through results
			
			$temp->set_member_id($result['member_id']);
			
			$temp->set_name($result['name']);
			
			$temp->set_password($result['password']);
			
			$temp->set_status($result['status']);
			
			$buffer[] = $temp;
		}
		
		return $buffer;
	
	}



	/////////////////////////////

	function _dal_acl_member(){
		//Destroys User  DALobject
		$this->_DBManager->Close();
	}//End User DAL Destructor
}//End class
?>
